package TP2.sorters;

import anaydis.sort.SorterType;

import java.util.Comparator;
import java.util.List;

public class InsertionSorter extends AbstractSorter {

    public InsertionSorter(){
        this(SorterType.INSERTION);
    }

    protected InsertionSorter(final SorterType type){
        super(type);
    }

    public <T> void sort(Comparator<T> comparator, List<T> list){
        int n = list.size();
        for (int i = 0; i < n; i++){
            for (int j = i; j > 0; j--){
                if (greater(comparator, list, j-1, j)){
                    swap(list, j, j-1);
                }else {
                    break;
                }
            }
        }
    }

}
